angular.module('mamApp').controller('chooseCPModalController', ['$scope', 'ContractManagementManager', '$state', '$uibModal', 'ImsDialog', '$uibModalInstance', 'CommonManager',
    function ($scope, ContractManagementManager, $state, $uibModal, ImsDialog, $uibModalInstance, CommonManager) {
        $scope.total = 0;
        $scope.table = JSON.parse(localStorage.getItem("codeTable"));
        $scope.Ok = function () {
            $uibModalInstance.close($scope.data);
        };
        $scope.fileNames = [{key: "", value: "查找字段"},
            {key: "cpId", value: "CP_ID"},
            {key: "nickName",value: "昵称"},
            {key: "userName", value: "账户名"}];
        $scope.search = {reviewStatus: 8,key:""};

        $scope.cancel = function () {
            $uibModalInstance.dismiss("cancel");
        };
        $scope.signs = [{key: 30, value: $scope.table[30]}, {key: 31, value: $scope.table[31]}];
        $scope.levels = [{key: 20, value: $scope.table[20]}, {key: 21, value: $scope.table[21]}, {
            key: 22,
            value: $scope.table[22]
        }];
        $scope.propertyes = [
            {key: 12, value: $scope.table[12]},
            {key: 13, value: $scope.table[13]}
        ];

        $scope.cpTypes = [
            {key: 41, value: $scope.table[41]},
            {key: 51, value: $scope.table[51]},
            {key: 52, value: $scope.table[52]},
            {key: 53, value: $scope.table[53]},
            {key: 54, value: $scope.table[54]}
        ];

        $scope.paginationConf = {
            currentPage: 1,
            itemsPerPage: 5,
            pagesLength: 9,
            perPageOptions: [10, 20, 30, 40, 50],
            search: true,
            onChange: function () {
                getCpList(this.currentPage, this.itemsPerPage, $scope.search);
            }
        };
        $scope.total = 0;
        $scope.table = JSON.parse(localStorage.getItem("codeTable"))
        $scope.$parent.allChecked = false;
        $scope.tmpSelect = [];

        var getCpList = function (pageNo, pageSize, query) {
            CommonManager.cpList([pageNo, pageSize], query).then(function (result) {
                $scope.CPExamine = result.data.pageList;
                $scope.paginationConf.totalItems = result.data.total;

            })
        }
        $scope.searchClick=function (event) {
            if(event&&event.key=="Enter"||!event){
                getCpList(1,5,$scope.search);
            }
        }

        $scope.selectChange = function () {
            getCpList(1, 5, $scope.search);
        }
        $scope.CPExamineCheck = function (CPExamine) {
            $scope.data = CPExamine;
            $uibModalInstance.close($scope.data);

        }

    }])

